﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Serialization;
using Devtm.ServiceModel.Configurations;
using Devtm.ServiceModel.Helpers;
using System.Xml.Linq;

namespace Devtm.ServiceModel.Discovery
{

    [Serializable]
    public class Extension
    {


        #region Ctor

        public static Extension GetService()
        {
            return new Extension()
            {
                Mode = Constantes.ModeContainer.Service,
                ApplicationId = LocatorSection.OptimistConfiguration.ApplicationId,
                NotifyCriterias = new NotifyCriterias()
            };
        }

        public static Extension GetPublishSubscribe()
        {
            return new Extension()
            {
                Mode = Constantes.ModeContainer.PublishSubscribe,
                ApplicationId = LocatorSection.OptimistConfiguration.ApplicationId,
                NotifyCriterias = new NotifyCriterias()
            };
        }

        public static Extension GetMetadata()
        {
            return new Extension()
            {
                Mode = Constantes.ModeContainer.MetadataExchange,
                ApplicationId = LocatorSection.OptimistConfiguration.ApplicationId,
                NotifyCriterias = new NotifyCriterias()
            };
        }

        public static Extension GetMeta()
        {
            return new Extension()
            {
                Mode = Constantes.ModeContainer.Meta,
                ApplicationId = LocatorSection.OptimistConfiguration.ApplicationId,
                NotifyCriterias = new NotifyCriterias()
            };
        }

        #endregion

        public Extension()
        {

        }

        [XmlAttribute]
        public string Mode { get; set; }

        [XmlAttribute]
        public Guid ApplicationId { get; set; }


        public System.Xml.Linq.XElement Data { get; set; }

        public static System.Xml.Linq.XElement Serialize(Extension item)
        {
            string txt = item.SerializeXml();
            return new XElement("config", new XCData(txt));
        }

        internal static Extension UnSerialize(XElement x1)
        {
            var txt = x1.Value;
            Extension e = Xml.UnSerializeXml<Extension>(txt);
            return e;
        }

        public NotifyCriterias NotifyCriterias { get; set; }

    }






    [Serializable]
    public class NotifyCriterias
    {


        public NotifyCriterias()
        {
            Contract = new ContractCriteria();
        }

        public ContractCriteria Contract { get; set; }

    }


    [Serializable]
    public class ContractCriteria
    {

        public string Namespace { get; set; }

        public string Name { get; set; }
    }

}
